<?php
/**
 * Created by PhpStorm.
 * User: jimmy
 * Date: 2018/1/2
 * Time: 下午5:41
 */
/**
 * Created by PhpStorm.
 * User: frankpian
 * Date: 17-12-5
 * Time: 上午10:55
 */


class BatteryStatController extends CloudControllerBase
{


    public function listAction(){
        if (!$this->isMonitorAdminUser()) {
            $this->transferErrorPage("权限错误", "操作权限错误");
        }
        $action = $this->getRequestAction();
        switch ($action) {
            case  $this::REQUEST_ACTION_DELETE: {

                if ($this->isSubsystemExistUsers()) {
                    $this->returnError("错误,系统下面存在用户,无法删除对应系统");
                }
                if ($this->isSubsystemExistPlanes()) {
                    $this->returnError("错误,系统下面存在飞机,无法删除对应系统");
                }
                $this->generateDeleteData(array(
                    "table" => "subsystem_info",
                    "paramList" => array(
                        ["id", "="],
                        ["batch_keys", "in", "(", ")", "id"],
                        ["system_name", "like", "%", "%"],
                        ['system_title', 'like', '%', '%'],
                        ['created_at_start', '>=', '', '', "created_at"],
                        ['created_at_end', '<=', '', '', "created_at"]
                    ),
                    "where" => " not id=1",
                ));

            };
                break;
            case  $this::REQUEST_ACTION_LIST: {

                $tableName = "(SELECT
	uas.uas_serial_id,
	mis.local_id,
	survey_area_name,
	uas.created_at,
	mis.flight_task_id to_flight_task_id,
	mis.project_id to_project_id
FROM
	flight_mission AS mis
INNER JOIN (
	SELECT
		*
	FROM
		uas_status
	GROUP BY
		flight_mission_id
) AS uas ON uas.flight_mission_id = mis.id)";

                $this->postQueryByPage(array(
                    "uas_serial_id" => "飞机序列号",
                    "local_id" => "架次ID",
                    "to_project_id" => "项目名称",
                    "to_flight_task_id" => "任务名称",
                    "survey_area_name" => "测区名称",
                    "created_at" => "创建时间",
                ), $tableName, array(
                    ["system_name", "like", "%", "%"],
                    ['system_title', 'like', '%', '%'],
                    ['created_at_start', '>=', '', '', "created_at"],
                    ['created_at_end', '<=', '', '', "created_at"]
                ), "created_at desc", "id");

            };
                break;
            default: {
                //查询相关的动作
                $roleData = $this->fetchAll("select id,user_role_name from user_role ");
                $this->view->setVars(array("roleData" => json_encode($roleData)));
            };
                break;
        }
    }
}